//
//  StatusCellTopView.swift
//  Sina
//
//  Created by maling  on 15/11/10.
//  Copyright © 2015年 maling . All rights reserved.
//

import UIKit
//import 
class StatusCellTopView: UIView {

    // 定义视图模型 - 给属性赋值
    var viewModel: StatusViewModel? {
    
        didSet {
            // 姓名
            nameLabel.text = viewModel?.status.user?.screen_name
            // 头像
            iconView.sd_setImageWithURL(viewModel?.userProfileUrl, placeholderImage: viewModel?.userDefaultIconView)
            // 会员图标
            memberIconView.image = viewModel?.userMemberImage
            // 认证图标
            vipIconView.image = viewModel?.userVipImage
            
            //TODO: - 设置时间，来源设置
            timeLabel.text = "刚刚"     // viewModel.status.created_at
            sourceLabel.text = "来自黑马微博"   // viewModel.status.source
            
            
        }
    }
    
    // MARK: - 构造函数
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    
    
    //MARK: - 懒加载控件
/// 头像
    private lazy var iconView: UIImageView = UIImageView(imageName: "avatar_default_big")
/// 姓名
    private lazy var nameLabel: UILabel = UILabel(title: "烽火恋晨", fontSize: 14, color: UIColor.magentaColor())
/// 会员图标
    private lazy var memberIconView: UIImageView = UIImageView(imageName: "common_icon_membership_level1")
/// 认证图标
    private lazy var vipIconView: UIImageView = UIImageView(imageName: "avatar_vip")
/// 时间标签
    private lazy var timeLabel: UILabel = UILabel(title: "刚刚", fontSize: 12, color: UIColor.orangeColor())
/// 来源标签
    private lazy var sourceLabel: UILabel = UILabel(title: "新浪微博", fontSize: 12)
    
    
    
}

// MARK: - 设置界面
extension StatusCellTopView {

    private func setupUI() {
    
        
        // 0. 添加一个分割视图（每一个cell都有一个分割cell）
        let sepView = UIView()
        sepView.backgroundColor = UIColor.lightGrayColor()
        addSubview(sepView)
        
        
        //设置底部视图View的颜色
//        backgroundColor = UIColor(white: 0.85, alpha: 1)
//        backgroundColor = UIColor.darkGrayColor()
        
        
        // 1.添加控件
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memberIconView)
        addSubview(vipIconView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        // 2. 设置自动布局
        // 0.设置分割视图的自动布局
        sepView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.right.equalTo(self.snp_right)
            make.height.equalTo(statusCellMargin)
        }
        // 1》 设置头像自动布局
        iconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(sepView.snp_bottom).offset(statusCellMargin)
            make.left.equalTo(self.snp_left).offset(statusCellMargin)
            make.width.equalTo(StatusCellIconWith)
            make.height.equalTo(StatusCellIconWith)
            
        }
        // 2> 设置昵称自动布局
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconView.snp_right).offset(statusCellMargin)
            make.top.equalTo(iconView.snp_top)
            
        }
        // 3> 设置会员图标
        memberIconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(nameLabel.snp_right).offset(statusCellMargin)
            make.top.equalTo(nameLabel.snp_top)
        }
        // 4》 设置认证图标
        vipIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right)
            make.centerY.equalTo(iconView.snp_bottom)
            
        }
        // 5> 设置时间标签
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconView.snp_right).offset(statusCellMargin)
            make.bottom.equalTo(iconView.snp_bottom)
        }
        // 6> 设置来源标签
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLabel.snp_right).offset(statusCellMargin)
            make.top.equalTo(timeLabel.snp_top)
        }
        
    }

}















